define([
        'underscore',
        'plupload/plupload.full.min',
        'app/utils/CommonUtils'
        ], function (
		_
    ) {

	

	var uploader = {};
	
	

	var s = {};
	
	var base = "";
	
	s.initSingleImage = function(containerId, browseButtonId, url, Completed_Func){
		
		uploader = new plupload.Uploader({
			runtimes : 'html5,flash,silverlight,html4',
			browse_button : browseButtonId, // you can pass an id...
			container: document.getElementById(containerId), // ... or DOM Element itself
			url : url,//'upload.php',
			flash_swf_url : base + 'assets/js/plupload/Moxie.swf',
			silverlight_xap_url : base + 'assets/js/plupload/Moxie.xap',
			
			filters : {
				max_file_size : '1mb',
				mime_types: [
					{title : "Image files", extensions : "jpg,png"}
				]
			},
			auto_start: true,  
			multi_selection: false,
			chunk_size: '1mb',                  // 分块上传时，每块的体积

			init: {
				PostInit: function() {
	
				},

	            FileUploaded: function(up, file, info) {
	                // Called when file has finished uploading
					//"{"status":"200","result":{"path":"http://localhost:8014/attachment/img/ac3f7f1d-4462-4362-8363-8a08826ebe82","key":"ac3f7f1d-4462-4362-8363-8a08826ebe82"}}"
					
					Completed_Func(up, file,info);
					
	            },
				UploadComplete: function(up, files) {
		            //队列文件处理完毕后,处理相关的事情
//					Completed_Func(up, files);
		        },
		        
				FilesAdded: function(up, files) {
					uploader.start();
					//FilesAdded_Func(up,files);
//					plupload.each(files, function(file) {
//						document.getElementById('filelist').innerHTML += '<div id="' + file.id + '">' + file.name + ' (' + plupload.formatSize(file.size) + ') <b></b></div>';
//					});
				},
				

				UploadProgress: function(up, file) {
//					UploadProgress_Func(up, file);
//					document.getElementById(file.id).getElementsByTagName('b')[0].innerHTML = '<span>' + file.percent + "%</span>";
				},

				Error: function(up, err) {
					//document.getElementById('console').appendChild(document.createTextNode("\nError #" + err.code + ": " + err.message));
//					Error_Func(up,err);
					console.log(up);
					console.log(err);
				}
			}
		});
		
		uploader.init();
		
	}
	
	s.startUpload = function(){
		//开始上传
		uploader.start();
	};
	
	return s;
});

